Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render snapshot for VM #190

Merged
merged 1 commit into from
Feb 27, 2018
Merged

Conversation

sasoc
Copy link
Contributor

@sasoc sasoc commented Feb 23, 2018

Refresh parser now renders snapshot for VM.
VCloud only returns creation time, size and
poweredOn, which tells if if the virtual machine was
powered on when the snapshot was created. So uid and
ems_ref are created from VM's id and creation time
of snapshot.

BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1550906

@sasoc
Copy link
Contributor Author

sasoc commented Feb 23, 2018

cc @miha-plesko

@@ -134,13 +134,30 @@ def parse_vm(vm)
}
end

snapshot_resp = vm.service.get_snapshot_section(vm.id).data[:body][:Snapshot]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make a helper function to retrieve the snapshot

@@ -134,13 +134,30 @@ def parse_vm(vm)
}
end

snapshot_resp = vm.service.get_snapshot_section(vm.id).data[:body][:Snapshot]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use @connection instead of vm.service.

snapshot = [
{
:name => "#{vm.name}(snapshot)",
:uid => "#{vm.id}-#{snapshot_resp[:created]}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked if the href attribute could be used (or part thereof) for the uid and ems_ref?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I have checked, href only contains id of VM.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a different seperator than '-' since that is part of the uuid already? That way you can split the uid apart with something like snapshot.uid.split("__")

@@ -58,6 +58,18 @@
end
end

it "will perform refresh for snapshot" do
2.times do # Run twice to verify that a second run with existing data does not change anything
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you separating this to have a different VCR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we talked about it with @miha-plesko and decided to create a new VCR.

@agrare agrare self-assigned this Feb 26, 2018
@agrare
Copy link
Member

agrare commented Feb 26, 2018

@sasoc looks like this needs a new VCR recording cc @gberginc

@@ -217,4 +218,24 @@ def parse_vapp_template(vapp_template)

return uid, new_result
end

def parse_snapshot(vm)
snapshot_resp = @connection.get_snapshot_section(vm.id).data[:body][:Snapshot]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use data.fetch_path(:body, :Snapshot) here so we fail the refresh with an exception if body is somehow nil

snapshot = [
{
:name => "#{vm.name}(snapshot)",
:uid => "#{vm.id}-#{snapshot_resp[:created]}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a different seperator than '-' since that is part of the uuid already? That way you can split the uid apart with something like snapshot.uid.split("__")

Copy link
Contributor

@miha-plesko miha-plesko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sasoc some minor comments. To make the old VCR spec green again, please mock parse_snapshot function there.

@@ -141,6 +141,7 @@ def parse_vm(vm)
:name => name,
:vendor => "vmware",
:raw_power_state => status,
:snapshots => parse_snapshot(vm),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:snapshots => [parse_snapshot(vm)].compact,

Nitpicking, but can you please use such format ^, it's annoying if we say "parse (single) snapshot" and then return a list :)

]
end

snapshot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could simplify the whole function:

resp = @connection.get_snapshot_section(vm.id).data
if (snapshot_resp = resp.fetch_path(:body, :Snapshot))
  {
    :name        => "#{vm.name}(snapshot)",
    :uid         => "#{vm.id}-#{snapshot_resp[:created]}",
    ...
  }
end

@sasoc sasoc force-pushed the render-snapshot-for-vm branch 2 times, most recently from 895e331 to c975370 Compare February 27, 2018 13:08
end

snapshot
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def parse_snapshot(vm)
    resp = @connection.get_snapshot_section(vm.id).data
    if (snapshot_resp = resp.fetch_path(:body, :Snapshot))
      {
        :name        => "#{vm.name} (snapshot)",
        :uid         => "#{vm.id}_#{snapshot_resp[:created]}",
        :ems_ref     => "#{vm.id}_#{snapshot_resp[:created]}",
        :parent_id   => vm.id,
        :parent_uid  => vm.id,
        :create_time => snapshot_resp[:created],
        :total_size  => snapshot_resp[:size]
      }
   else
     nil
   end    
end

@@ -40,6 +40,8 @@
end

it "will perform a full refresh" do
allow_any_instance_of(ManageIQ::Providers::Vmware::CloudManager::RefreshParser).to receive(:parse_snapshot).and_return(nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Mock snapshot collection since VCR cassete does not contain those request yet.
# TODO: record a new VCR cassette when provider development is done.
allow_any_instance_of(described_class).to receive(:parse_snapshot).and_return(nil)

@sasoc sasoc force-pushed the render-snapshot-for-vm branch 2 times, most recently from 87fe4cd to 8d7f84b Compare February 27, 2018 14:09
@miha-plesko miha-plesko force-pushed the render-snapshot-for-vm branch 2 times, most recently from 9e84bcd to 678825c Compare February 27, 2018 14:43
With this commit we support VM snapshot inventoring. Since vCloud is
quite modes with information it reveals about VM snapshots (only creation time,
size and poweredOn, which tells if if the virtual machine was powered on when the
snapshot was created) we need to compose `uid` and `ems_ref` dynamically.

Signed-off-by: Miha Pleško <miha.plesko@xlab.si>
Signed-off-by: Sašo Cvitkovič <saso.cvitkovic@xlab.si>
@miq-bot
Copy link
Member

miq-bot commented Feb 27, 2018

Checked commit sasoc@a8eb345 with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0
4 files checked, 1 offense detected

**

  • 💣 💥 🔥 🚒 - Linter/Yaml - missing config files

@miha-plesko
Copy link
Contributor

@miq-bot add_label enhancement,gaprindashvili/yes

Copy link
Member

@agrare agrare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 looks good, nice tests

@agrare agrare merged commit a8eb345 into ManageIQ:master Feb 27, 2018
agrare added a commit that referenced this pull request Feb 27, 2018
@agrare agrare modified the milestones: Sprint 80 Ending Feb 26, 2018, Sprint 81 Ending Mar 12, 2018 Feb 27, 2018
@miha-plesko
Copy link
Contributor

simaishi pushed a commit that referenced this pull request Mar 7, 2018
@simaishi
Copy link
Contributor

simaishi commented Mar 7, 2018

Gaprindashvili backport details:

$ git log -1
commit 64c098ba52fc6f45935af2a017b9d24b2bec0513
Author: Adam Grare <agrare@redhat.com>
Date:   Tue Feb 27 13:26:57 2018 -0500

    Merge pull request #190 from sasoc/render-snapshot-for-vm
    
    Render snapshot for VM
    (cherry picked from commit 8b0d0e8a9e6e9dbe4702b426f961745fc44ba7b2)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1552686

agrare pushed a commit to agrare/manageiq-providers-vmware that referenced this pull request Apr 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants